﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using WoodAdmin.Common.Helper.Log;
using WoodAdmin.Models.ViewModels;
using System;

namespace WoodAdmin.Common.Filter
{
    /// <summary>
    /// 异常过滤器
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
    public class ApiExceptionHandle : ExceptionFilterAttribute
    {
        public override void OnException(ExceptionContext context)
        {
            NLogger.Debug($"请求出错啦~【{context.Exception.Message}】");
            ResultViewModel result = new ResultViewModel($"请求出错啦~【{context.Exception.Message}】", ResultCode.Error);
            context.Result = new JsonResult(result);
        }
    }
}
